﻿using System.Windows.Input;
using ESRI.ArcGIS.Client;
using Services.Maps;

namespace Apps.Maps
{
    public class RectZoomOut : MapToolsBase
    {
        public override void Show()
        {
            this.IsShowed = true;
            // 处理组件互斥操作。
            this.ExclusionWidget();
            if (ActiveMap == null) return;
            //拉框放大，改变鼠标，设定画图的类型
            ActiveMap.Cursor = Cursors.Arrow;
            drawTool_mainMap.IsEnabled = true;
            mapService.DrawComplete += new System.EventHandler<DrawEventArgs>(mapService_DrawComplete);
            mapService.DrawBegin -= null;

        }
        /// <summary>
        /// 为垃框放大做的画图结束处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void mapService_DrawComplete(object sender, DrawEventArgs e)
        {
            double mapHeight = mapService.CurrentMap.Extent.Height;
            double mapWidth = mapService.CurrentMap.Extent.Width;
            double recHeight = e.Geometry.Extent.Height;
            double recWidth = e.Geometry.Extent.Width;
            double fac = (recHeight + recWidth) / (mapHeight + mapWidth);
            mapService.CurrentMap.Zoom(fac);
        }
        public override void Close()
        {
            this.IsShowed = false;
            if (ActiveMap == null) return;
            drawTool_mainMap.IsEnabled = false;
            ActiveMap.Cursor = Cursors.Hand;
        }
    }
}
